#include "comm.hpp"
int main()
{
    bool r=createFifo(NAMED_PIPE);
    assert(r);
    (void)r;
    std::cout << "server begin" << std::endl;
    int rfd =open(NAMED_PIPE,O_RDONLY);//会等用户端打开管道文件，服务端才进行open服务端以只读的方式打开
    if(rfd==-1)//打开失败
        exit(1);
    //读取
    char buffer[1000];
    while(true)
    {
        ssize_t s=read(rfd,buffer,sizeof(buffer)-1);
        if(s>0)
        {
            buffer[s]=0;//将最后一个字符设置为'\0'
            std::cout<<"client->server:"<<buffer;
        }
        else if(s==0)//说明客户端一直没发数据
        {
            std::cout << "client quit, me too!" << std::endl;
            break;
        }
        else//读取出错
        {
            std::cout<<"err string"<<strerror(errno)<<std::endl;
            break;
        }
    }
    close(rfd);
    destroyFifo(NAMED_PIPE);
    return 0;
}